package ModelLayer;
import java.util.ArrayList;


public class Products
{
    //instance variables
    private static Products instance = null;
    private static ArrayList<SalesLine> products;
   
    /**
     * Empty constructor for testing purposes
     */
    
    private Products()
    {
       products = new ArrayList<SalesLine>();
    }
    
    /**
     * Singleton static inplementation
     */
    
    public static Products getInstance()
    {
        if(instance == null)
      {
        instance = new Products();
      }
      return instance;
    }
   
    /**
     * Accessor and Mutator methods
     */
    
    public static void addProduct(SalesLine _product)
    {
        products.add(_product);
    }
    
    public static SalesLine getProduct(String _id)
    {
        SalesLine o = new SalesLine();
        for(int i= 0; i<products.size(); i++)  
        {
            if (products.get(i).getId().equals(_id))
                o = products.get(i);
        }
        return o;
    }
    
    public static void printProducts()
    {
        System.out.println("\nProducts:");
        for(int i = 0; i < products.size(); i++)
        {
            System.out.println("\nId: " + products.get(i).getId() +
                                "\nName: " + products.get(i).getName());
        }
        
    }
    
    public static int getSize()
    {
        return products.size();
    }
}
